<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <input id="myInput" type="text">
  <script>
    const myInput = document.getElementById('myInput')
    const Ajax = function (e) {
      console.log(e)
    }
    let deBounce = (fn,delay)=> {
      let timer = null
      return function(...args){
        if (timer) clearTimeout(timer)
        timer = setTimeout(()=>{
          console.log('----------------')
          fn(...args)
          // clearTimeout(timer)
        },delay)
      }
    }
    let doAjax = deBounce(Ajax,2000)
    myInput.addEventListener('keyup',(e)=>{
      doAjax(e.target.value)
    })
  </script>
</body>
</html>